package com.channel.springcloudserviceprotal.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfig {

    @LoadBalanced // 使用Ribbon实现负载均衡的调用 (Spring Cloud -> 封装ribbon + eureka + restTemplate)
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 切换负载均衡策略，配置一个负载均衡策略的bean即可
     * @return
     */
    @Bean
    public IRule iRule(){
        return new MyRule();
    }
}
